//
//  WBVisitorViewController.swift
//  WeiBo
//
//  Created by 韩菲菲 on 16/8/9.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

import UIKit

class WBVisitorViewController: UIViewController {
    
    //懒加载一个tableView
    lazy var tableView : UITableView = UITableView()
    
    //判断用户是否登录
    var isLogin: Bool = WBUserAccountViewModel.sharedUserAccountViewModel.isLogin
    
    var visitorView : WBVisitorView?
    
    override func loadView() {
        
        if isLogin{
        //登录了
         view = tableView
        
        }else
        {
            setNavBtn()
            visitorView = WBVisitorView()
         
            //实例化闭包
            visitorView?.closure = {
              
              self.navBtnClick()
            }
            
            view = visitorView
            
            view.backgroundColor = UIColor(red: 237/255.0, green: 237/255.0, blue: 237/255.0, alpha: 1)
        
        }
    
    }
    
    //设置导航按钮
    func setNavBtn() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(WBVisitorViewController.navBtnClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(WBVisitorViewController.navBtnClick))
        
        
    }
    
    //注册 登录 按钮的点击事件的实现
    func navBtnClick() {
        
        let oAuthVc = WBOAuthViewController()
        
        //modal一个控制器
        presentViewController(UINavigationController(rootViewController: oAuthVc), animated: true, completion: nil)
        
        
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    


}
